package com.lkm.market2_0;

import android.content.Context;

import com.lkm.frame.exception.NotHaveMemoryException;
import com.lkm.frame.file.FileSystem;
import com.lkm.frame.module.ModuleManager;
import com.lkm.frame.task2.TaskManager;
import com.lkm.market2_0.entity.ResponEntity;

import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.Executor;

public class Market2_0ConfigeImpl extends Config {

    @Override
    public String interceptNetApi(String taskId) {
        return null;
    }

    @Override
    public String instask(String taskId, ResponEntity re, String json) {
        return null;
    }

    @Override
    public boolean isUI() {
        return false;
    }

    @Override
    public String getServerApiHost() {
        return MyApplication.getInstance().getSharedPreferences("settingapp",Context.MODE_PRIVATE).getString("tv_url", "http://zhongzi.web.ic1986.com/api/tc.ashx");//"http://192.168.1.172:8080/api/xx.jsp");
    }

    @Override
    public InputStream getHttpsCertificates() {
        try {
            return MyApplication.getInstance().getResources().getAssets().open( "astracedev.crt");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int steelyardServerPort() {
        return 47111;
    }

    @Override
    public boolean isDebug() {
        return MyApplication.getInstance().isDebug();
    }

    @Override
    public boolean isTest() {
        return true;
    }

    @Override
    public void saveValue(String key, String value) {
        MyApplication.getInstance().getSharedPreferences("privateConfige", Context.MODE_PRIVATE).edit().putString(  key,value).apply();
    }

    @Override
    public String loadValue(String key,String default_) {
        return  MyApplication.getInstance().getSharedPreferences("privateConfige", Context.MODE_PRIVATE).getString(key, default_);
    }

    @Override
    public void showLogInUI(final String log) {
        if(MainActivity.mainActivity!=null){
            MainActivity.mainActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if(MainActivity.tv_logs!=null){
                        MainActivity.tv_logs.setText(log);//(stringBuilder.toString());
                    }

                }
            });

        }
    }

    @Override
    public TaskManager getTaskManager2() {
        return MyApplication.getInstance().getTaskManager2();
    }

    @Override
    public ModuleManager getModuleManager() {
        return MyApplication.getInstance().getModuleManager();
    }

    @Override
    public void acquireWakeLock(int timeout) {
        MyApplication.getInstance().acquireWakeLock(timeout);
    }

    @Override
    public void releaseWakeLock() {
        MyApplication.getInstance().releaseWakeLock();
    }

    @Override
    public Executor getTaskExecutor() {
        return com.lkm.comlib.Config.getTaskExecutor();
    }

    @Override
    public String getOrderTempFileDir() {
//        try {
//            return FileSystem.getWritePath(FileSystem.FileLocal.ExternalFilesDir, "orderTempFile", 100, MyApplication.application);
//        } catch (NotHaveMemoryException e) {
//            e.printStackTrace();
//        }
//        return "";
        return FileSystem.getRederPath(FileSystem.FileLocal.ExternalFilesDir, "orderTempFile", MyApplication.application);
    }

    @Override
    public String getUIast_oid() {
        return null;
    }
}
